using System;
using System.Windows;
using System.Windows.Data;
using NUnit.Framework;

namespace WPFUtilities
{
    public static class AssertBinding
    {
        public static void IsDataBound(DependencyObject dependencyObject, DependencyProperty property)
        {
            if(!BindingOperations.IsDataBound(dependencyObject, property))
            {
                throw new Exception(string.Format("{0} is not databound.", property.Name));
            }
        }

        public static void IsBoundToPath(DependencyObject target, DependencyProperty property, string path)
        {
            Binding binding = BindingOperations.GetBinding(target, property);
            string actualPath = binding.Path.Path;
            Assert.AreEqual(path, actualPath);
        }

        public static void IsSourceEqual(DependencyObject target, DependencyProperty property, object dataItem)
        {
            BindingExpression expression = BindingOperations.GetBindingExpression(target, property);
            Assert.AreEqual(dataItem, expression.DataItem);
        }
    }
}
